package me.xiaoyan.ehr.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class StringUtil {
    public static boolean isEmpty(String source) {
        return source == null || source.length() == 0;
    }
    /**
     * 转换request 请求参数
     *
     * @param paramMap request获取的参数数组
     */
    public static Map<String, String> convertParamMap(Map<String, String[]> paramMap) {
        Map<String, String> rtnMap = new HashMap<String, String>();
        for (String key : paramMap.keySet()) {
            rtnMap.put(key, paramMap.get(key)[0]);
        }
        return rtnMap;
    }

    public static String generateCode(int length){
        return String.valueOf(Math.random()).substring(2,length + 2);
    }
    public static String formatDate(String format,Date date) {

        SimpleDateFormat dateFormat = new SimpleDateFormat("yyy-MM-dd HH:mm:ss");
        return dateFormat.format(date);
    }
    public static String formatDate(String format) {
        return formatDate(format,new Date());
    }
}
